package com.ruoyi.web.controller.function;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.entity.DiseaseInfo;
import com.ruoyi.system.service.DiseaseInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author Y·C
 * @version 1.0.0
 * @ClassName DiseaseInfoController.java
 * @Description TODO
 * @createTime 2023年11月19日 20:49:00
 */
@Api(tags = "病情信息接口")
@RestController
@RequestMapping("/diseaseInfo")
public class DiseaseInfoController extends BaseController {

    @Autowired
    private DiseaseInfoService diseaseInfoService;


    /**
     * 根据隔离人员id获取病情信息
     * */
    @ApiOperation(value = "根据隔离人员id获取病情信息")
    @Anonymous
    @GetMapping("/getDiseaseInfoByGlPeopleId/{userId}")
    public AjaxResult getDiseaseInfoByGlPeopleId(@PathVariable("userId") Long userId) {

        List<DiseaseInfo> diseaseInfoList =  diseaseInfoService.getDiseaseInfoByGlPeopleId(userId);

        return AjaxResult.success(diseaseInfoList);
    }


    /**
     *  查询病情信息列表
     * */
    @ApiOperation(value = "查询病情信息列表")
    @GetMapping("/getDiseaseInfoList")
    @Anonymous
    public TableDataInfo getDiseaseInfoList(DiseaseInfo diseaseInfo) {
        startPage();
        List<DiseaseInfo> diseaseInfoList =  diseaseInfoService.getDiseaseInfoList(diseaseInfo);

        return getDataTable(diseaseInfoList);
    }

    /**
     * 根据diseaseId获取病情信息
     * */
    @ApiOperation(value = "根据diseaseId获取病情信息")
    @GetMapping("/getDiseaseInfoByDiseaseId/{diseaseId}")
    @Anonymous
    public AjaxResult getDiseaseInfoByDiseaseId(@PathVariable("diseaseId") Long diseaseId) {
        DiseaseInfo diseaseInfo = diseaseInfoService.getById(diseaseId);
        return AjaxResult.success(diseaseInfo);
    }

    /**
     * 新增病情信息
     * */
    @ApiOperation(value = "新增病情信息")
    @PostMapping("/addDiseaseInfo")
    @Anonymous
    public AjaxResult addDiseaseInfo(@RequestBody DiseaseInfo diseaseInfo) {
        return toAjax(diseaseInfoService.save(diseaseInfo));
    }
    /**
     *删除病情信息
     * */
    @ApiOperation(value = "删除病情信息")
    @DeleteMapping("/deleteDiseaseInfo")
    @Anonymous
    public AjaxResult deleteDiseaseInfo(@RequestBody List<Long> diseaseIds) {
        return toAjax(diseaseInfoService.removeByIds(diseaseIds));
    }

    /**
     * 修改病情信息
     * */
    @ApiOperation(value = "修改病情信息")
    @PutMapping("/updateDiseaseInfo")
    @Anonymous
    public AjaxResult updateDiseaseInfo(@RequestBody DiseaseInfo diseaseInfo) {
        return toAjax(diseaseInfoService.updateById(diseaseInfo));
    }

    @Anonymous
    @ApiOperation(value = "导出病情信息")
    @RequestMapping("/export")
    public void export(HttpServletResponse response, DiseaseInfo diseaseInfo){

        List<DiseaseInfo> list = diseaseInfoService.getDiseaseInfoList(diseaseInfo);
        ExcelUtil<DiseaseInfo> util = new ExcelUtil<>(DiseaseInfo.class);
        util.exportExcel(response, list, "病情信息表");
    }

}
